package com.portal.controller;

import com.portal.service.StudentService;
import com.test.api.CommonResult;
import com.test.model.Grade;
import com.test.model.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Api(value = "UserController",description = "学生接口")
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @ApiOperation("获取学生列表")
    @PostMapping("/getStudentList")
    public CommonResult<List<Student>> getStudentList(@ApiParam("单页大小")@RequestParam("pageSize") int pageSize,
                                                      @ApiParam("页数")@RequestParam("pageNum")int pageNum){
        List<Student> studentList = studentService.getStudentList(pageSize, pageNum);

        return CommonResult.success(studentList,"返回成功");
    }

    @ApiOperation("获取根据学生id获取班级信息")
    @PostMapping("/getGradeByStudentId")
    public CommonResult<Grade> getGradeByStudentId(@ApiParam("学生id")@RequestParam("studentId") Long studentId){
        Grade grade = studentService.getGradeByStudentId(studentId);

        return CommonResult.success(grade,"返回成功");
    }

    @ApiOperation("根据年级名字获取所有学生信息")
    @PostMapping("/getStudentByGradeName")
    public CommonResult<List<Student>> getStudentByGradeName(@ApiParam("年级名字")@RequestParam("gradeName") String gradeName){
        List<Student> studentByGradeName = studentService.getStudentByGradeName(gradeName);

        return CommonResult.success(studentByGradeName,"返回成功");
    }

}
